package cn.dyw.shop.model;
// Generated 2018-5-12 11:57:12 by Hibernate Tools 5.1.0.Alpha1

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Order generated by hbm2java
 */
@JsonIgnoreProperties(value={"handler", "hibernateLazyInitializer", "fieldHandler"})
@Entity
@Table(name = "order", catalog = "shop")
public class Order implements java.io.Serializable {

	private Integer id;
	private Address address;
	private User user;
	private BigDecimal totalPrice;
	private Boolean pay;
	private List<OrderItem> orderItems = new ArrayList<>(6);

	public Order() {
	}

	public Order(User user) {
		this.user = user;
	}

    public Order(Address address, User user, BigDecimal totalPrice, Boolean pay, List<OrderItem> orderItems) {
        this.address = address;
        this.user = user;
        this.totalPrice = totalPrice;
        this.pay = pay;
        this.orderItems = orderItems;
    }

	@Id
	@GeneratedValue(strategy = IDENTITY)

	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@JsonManagedReference
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "address_id")
    public Address getAddress() {
        return this.address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

	@JsonBackReference
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "total_price", precision = 8)
	public BigDecimal getTotalPrice() {
		return this.totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

	@Column(name = "pay")
	public Boolean getPay() {
		return this.pay;
	}

	public void setPay(Boolean pay) {
		this.pay = pay;
	}

	@JsonManagedReference
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "order")
	public List<OrderItem> getOrderItems() {
		return this.orderItems;
	}

	public void setOrderItems(List<OrderItem> orderItems) {
		this.orderItems = orderItems;
	}

}
